﻿namespace NGroup.VTL.Web.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Threading;
    using System.Globalization;
    using NGroup.VTL.Core.Const;

    public class ContentBaseController : Controller
    {
        protected LanguageCodes CurrentLanguage
        {
            get
            {
                HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies.Get(NGroup.VTL.Core.Const.GeneralConfiguration.LanguageCookieName);

                if (cookie != null)
                {
                    if (string.Equals(cookie.Value, LanguageCodes.en.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        return LanguageCodes.en;
                    }                    
                }

                return LanguageCodes.vi;                
            }
        }

        //public ContentBaseController()
        //{
        //    if (string.Equals("en", Thread.CurrentThread.CurrentUICulture.Parent.Name, StringComparison.OrdinalIgnoreCase))
        //    {
        //        CurrentLanguage = LanguageCodes.en;


        //    }
        //    else
        //    {
        //        CurrentLanguage = LanguageCodes.vi;
        //    }
        //}

        [HttpPost]
        public ActionResult ChangeLanguage(string lang)
        {
            if (Request.UrlReferrer != null)
            {
                return Redirect(Request.UrlReferrer.AbsolutePath);
            }
            else
            {
                return Redirect("/");
            }
        }
    }
}
